﻿function Novanet() { }
Novanet.prototype.getBrowser = function () {
    var nVer = navigator.appVersion;
    var nAgt = navigator.userAgent;
    var browserName = navigator.appName;
    var fullVersion = '' + parseFloat(navigator.appVersion);
    var majorVersion = parseInt(navigator.appVersion, 10);
    var nameOffset, verOffset, ix;
    var browsers = new Array();
    browsers[0] = "0";
    browsers[1] = "0";
    // In Opera, the true version is after "Opera" or after "Version"
    if ((verOffset = nAgt.indexOf("Opera")) != -1) {
        browserName = "1";
        fullVersion = nAgt.substring(verOffset + 6);
        if ((verOffset = nAgt.indexOf("Version")) != -1)
            fullVersion = nAgt.substring(verOffset + 8);
    }
    // In MSIE, the true version is after "MSIE" in userAgent
    else if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
        browserName = "2";
        fullVersion = nAgt.substring(verOffset + 5);
    }
    // In Chrome, the true version is after "Chrome" 
    else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
        browserName = "3";
        fullVersion = nAgt.substring(verOffset + 7);
    }
    // In Safari, the true version is after "Safari" or after "Version" 
    else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
        browserName = "4";
        fullVersion = nAgt.substring(verOffset + 7);
        if ((verOffset = nAgt.indexOf("Version")) != -1)
            fullVersion = nAgt.substring(verOffset + 8);
    }
    // In Firefox, the true version is after "Firefox" 
    else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
        browserName = "5";
        fullVersion = nAgt.substring(verOffset + 8);
    }
    // In most other browsers, "name/version" is at the end of userAgent 
    else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) <
        (verOffset = nAgt.lastIndexOf('/'))) {
        browserName = nAgt.substring(nameOffset, verOffset);
        fullVersion = nAgt.substring(verOffset + 1);
        if (browserName.toLowerCase() == browserName.toUpperCase()) {
            browserName = navigator.appName;
        }
    }
    // trim the fullVersion string at semicolon/space if present
    if ((ix = fullVersion.indexOf(";")) != -1)
        fullVersion = fullVersion.substring(0, ix);
    if ((ix = fullVersion.indexOf(" ")) != -1)
        fullVersion = fullVersion.substring(0, ix);

    majorVersion = parseInt('' + fullVersion, 10);
    if (isNaN(majorVersion)) {
        fullVersion = '' + parseFloat(navigator.appVersion);
        majorVersion = parseInt(navigator.appVersion, 10);
    }
    browsers[0] = browserName;
    browsers[1] = majorVersion;
    return browsers;
};
Novanet.prototype.getOS = function () {
    var osName = "0";
    if (navigator.appVersion.indexOf("Win") != -1) osName = "1"; //OSName="Windows";
    if (navigator.appVersion.indexOf("Mac") != -1) osName = "2"; //OSName="MacOS";
    if (navigator.appVersion.indexOf("X11") != -1) osName = "3"; //OSName="UNIX";
    if (navigator.appVersion.indexOf("Linux") != -1) osName = "4"; //OSName="Linux";
    return osName;
};

Novanet.prototype.GetParameterByName = function () {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
};
Novanet.prototype.CreateCookie = function (name, value, days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
};
Novanet.prototype.ReadCookie = function (name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
};
Novanet.prototype.EraseCookie = function (name) {
    this.CreateCookie(name, "", -1);
};

Novanet.prototype.ajaxGetData = function(url, idElementAppend) {
    var xmlhttp;
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new window.XMLHttpRequest();
    }
    else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById(idElementAppend).innerHTML = xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET", url, true);
    xmlhttp.send();
};
Novanet.prototype.init = function () {
    var browser = this.getBrowser();
    var browserName = browser[0];
    var browserVer = browser[1];
    var osName = this.getOS();
    var refer = encodeURIComponent(document.referrer);
    var historyLength = history.length;
    var host = encodeURIComponent(window.location.hostname);
    var url = encodeURIComponent(window.location.href);
    var osVer = "0";

    var id = 0;
    var nnc = this.ReadCookie("nnc");
    var cookieEnable = '';
    var newNNC = 'false';
    if (nnc > 0) {
        cookieEnable = 'true';
    } else {
        this.EraseCookie('nnc');
        this.CreateCookie('nnc', id, 90);
        nnc = this.ReadCookie("nnc");
        if (nnc == id) {
            newNNC = 'true';
            cookieEnable = 'true';
        }
        else
            cookieEnable = 'false';
    }

    var q = 'zone=' + novanet_zoneid + '&url=' + url + '&host=' + host + '&ref=' + refer + '&hl=' +
				historyLength + '&br=' + browserName + '&brver=' + browserVer + '&osname=' + osName +
				'&osver=' + osVer + '&width=' + novanet_width + '&height=' + novanet_height + '&time=' + (new Date()).getMilliseconds();
    var urlAdview = 'http://' + 'static.novanet.vn/adview.htm?' + q + "&nnc=" + nnc + '&cenable=' + cookieEnable + '&newnnc=' + newNNC;
    var iFrameAdview = '<iframe id="adviewIf' + novanet_zoneid + '" src="' + urlAdview + '" scrolling="no" frameborder="0" allowtransparency="true" style="margin:0;padding:0;" width="' + novanet_width + '" height="' + novanet_height + '"></iframe>';

    var gci = '<div id="novanetzone' + novanet_zoneid + '" style="display:block;overflow:hidden;margin:auto;text-align:center;width:'
        + novanet_width + 'px;height:' + novanet_height + 'px;">' + iFrameAdview + '</div>';
    gci = gci + '<div style="display:none;"><iframe width="1" scrolling="no" height="1" frameborder="0" src="' + 'http://' + 'imp.novanetservice.com/ga.html?utm_source=' + host + '"></iframe></div>';
    document.write(gci);
};

var novanetInstance = new Novanet();
novanetInstance.init();




